package jp.gr.java_conf.ryz.summarize.client.view;


import jp.gr.java_conf.ryz.summarize.client.presenter.PostDecoration;
import jp.gr.java_conf.ryz.summarize.client.presenter.PropertyChangedHandler;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.ListBox;

public class DecorationPanel extends FlowPanel
{
	private static final String DecorationPanelStyleName = "decorationPanel";
	
	private String _postNumber;
	private PostDecoration _decoration;
	private ListBox _fontSizeList;
	private CheckBox _isBoldCheck;
	
	
	/**
	 * constructor.
	 * 
	 * @param decoration {@link PostDecoration}
	 */
	public DecorationPanel(PostDecoration decoration, String postNumber)
	{
		super();
		
		_postNumber = postNumber;
		_decoration = decoration;
		
		init();
	}
	
	
	/**
	 * initialize.
	 */
	private void init()
	{
		_fontSizeList = new ListBox();
		_fontSizeList.addItem("文字サイズ", (String)null);
		_fontSizeList.addItem("1 (10px)", "10px");
		_fontSizeList.addItem("2 (13px)", "13px");
		_fontSizeList.addItem("3 (16px)", "16px");
		_fontSizeList.addItem("4 (18px)", "18px");
		_fontSizeList.addItem("5 (24px)", "24px");
		_fontSizeList.addItem("6 (32px)", "32px");
		_fontSizeList.addItem("7 (48px)", "48px");
		_fontSizeList.addChangeHandler(new ChangeHandler()
		{
			
			@Override
			public void onChange(ChangeEvent event)
			{
				int index = _fontSizeList.getSelectedIndex();
				_decoration.setFontSize(_fontSizeList.getValue(index));
			}
		});
		add(_fontSizeList);
		
		_isBoldCheck = new CheckBox("太文字");
		_isBoldCheck.addValueChangeHandler(new ValueChangeHandler<Boolean>()
		{
			@Override
			public void onValueChange(ValueChangeEvent<Boolean> event)
			{
				_decoration.setIsBold(event.getValue());
			}
		});
		add(_isBoldCheck);
		
		ColorPaletPanel colorPaletPanel = new ColorPaletPanel(_decoration, _postNumber);
		colorPaletPanel.addStyleName("toInline");
		add(colorPaletPanel);
		
		addDomHandler(new ClickHandler()
		{
			@Override
			public void onClick(ClickEvent event)
			{
				event.stopPropagation();
			}
		}, ClickEvent.getType());
		
		_decoration.addPropertyChangedHandler(new PropertyChangedHandler()
		{
			@Override
			public void OnPropertyChanged(Object sender, String propertyName)
			{
				if (propertyName.equals(PostDecoration.IsBoldPropertyName))
				{
					_isBoldCheck.setValue(_decoration.isBold());
				}
			}
		});
		
		addStyleName(DecorationPanelStyleName);
	}
}
